package top.goldenyear.porpoise.system.permission.controller.admin;

import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;
import top.goldenyear.porpoise.common.core.model.Ret;
import top.goldenyear.porpoise.framework.web.core.controller.BaseController;
import top.goldenyear.porpoise.framework.web.core.model.query.QPage;
import top.goldenyear.porpoise.system.permission.model.Role;
import top.goldenyear.porpoise.system.permission.service.RoleService;

/**
 * 角色表 Controller 控制层
 *
 * @author airhead
 * @since 2024-10-13
 */
@Component(tag = "adminApi")
@Mapping("/permission/role")
@Slf4j
public class RoleAdminController extends BaseController {
  @Inject private RoleService service;

  @Post
  @Mapping("create")
  public Ret create(@Body Role role) {
    return Ret.okWithData(service.createRole(role));
  }

  @Post
  @Put
  @Mapping("update")
  public Ret update(@Body Role role) {
    return Ret.okWithData(service.updateRole(role));
  }

  @Get
  @Mapping("get")
  public Ret get(@Param Integer id) {
    return Ret.okWithData(service.getRole(id));
  }

  @Post
  @Delete
  @Mapping("delete")
  public Ret delete(@Param Integer id) {
    return Ret.okWithData(service.deleteRole(id));
  }

  @Get
  @Mapping("paginate")
  public Ret paginate(QPage qPage) {
    Role role = getBean(Role.class);
    return Ret.okWithData(service.paginateRole(qPage, role));
  }

  @Get
  @Mapping("list")
  public Ret list() {
    Role role = getBean(Role.class);
    return Ret.okWithData(service.listRole(role));
  }
}
